class Solution {
    public int maxProfit(int[] prices) {
        int min_ = prices[0], max_=0;
        for (int price : prices) {
            min_ = Math.min(min_, price);
            max_ = Math.max(max_, price-min_);
        }
        return max_;
    }
}